// 客户端套接字 将数据发送给服务端

let net = require('net')
let client = new net.Socket()
client.setEncoding('utf8')

// connet to server
client.connect('3000', 'localhost', () => {
  console.log('Connected to server')
  client.write('Who needs a browser to communicate?')

})

// when receiver data , send to server
process.stdin.on('data', (data) => {
  client.write(data)
})

// when receive data back, print to console
client.on('data', (data) => {
  console.log(data)
})

//when server closed 
client.on('close', () => {
  console.log('connection  is closed')
})
